package com.criteria;

import com.criteria.filter.PersonCriteria;
import com.criteria.filter.implbase.PersonCriteriaFemale;
import com.criteria.filter.implbase.PersonCriteriaMale;
import com.criteria.filter.implbase.PersonCriteriaMarried;
import com.criteria.filter.implbase.PersonCriteriaSingle;
import com.criteria.filter.implextend.PersonAndCriteria;
import com.criteria.filter.implextend.PersonOrCriteria;
import com.criteria.po.Person;

import java.util.ArrayList;
import java.util.List;

public class Test {
    public static void main(String[] args) {
        // 创建一个列表
        List<Person> persons = new ArrayList<Person>();
        // 装载一些测试数据
        persons.add(new Person("Robert","Male", "Single"));
        persons.add(new Person("John","Male", "Married"));
        persons.add(new Person("Laura","Female", "Married"));
        persons.add(new Person("Diana","Female", "Single"));
        persons.add(new Person("Mike","Male", "Single"));
        persons.add(new Person("Bobby","Male", "Single"));

        PersonCriteria male = new PersonCriteriaMale();
        PersonCriteria female = new PersonCriteriaFemale();
        PersonCriteria single = new PersonCriteriaSingle();
        PersonCriteria married = new PersonCriteriaMarried();
        PersonCriteria singleAndMale = new PersonAndCriteria(single, male);
        PersonCriteria marriedOrFemale = new PersonOrCriteria(married, female);

        System.out.println("Males: ");
        printPersons(male.streamFilterCollect(persons));

        System.out.println("\nFemales: ");
        printPersons(female.streamFilterCollect(persons));

        System.out.println("\nMarried: ");
        printPersons(married.streamFilterCollect(persons));

        System.out.println("\nSingle: ");
        printPersons(single.streamFilterCollect(persons));

        System.out.println("\nSingle & Males: ");
        printPersons(singleAndMale.streamFilterCollect(persons));

        System.out.println("\nMarried Or Females: ");
        printPersons(marriedOrFemale.streamFilterCollect(persons));

    }

    public static void printPersons(List<Person> persons){
        for (Person person : persons) {
            System.out.println(person.toString());
        }
    }
}
